package com.joesem.sale.client.logic.workOrder

import android.os.Build.VERSION_CODES.P
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jiaxing.sale.client.R
import com.joesem.sale.client.network.data.WorkOrderMode
import com.joesem.sale.client.utils.click


class WorkOrderAdapter : BaseQuickAdapter<WorkOrderMode, BaseViewHolder>(R.layout.item_work_order) {
    var itemClick: (WorkOrderMode) -> Unit = {}
    override fun convert(holder: BaseViewHolder, item: WorkOrderMode) {
        holder.setText(R.id.tvTitle, item.type.orEmpty())
        holder.setText(R.id.tvStatus, item.status.orEmpty())
        holder.setText(R.id.tvCustomer, "客户：${item.customer?.name.orEmpty()}")
        holder.setText(R.id.tvOrderNo, "工单号：${item.wo_number.orEmpty()}")
        holder.setText(R.id.tvCustomerAddress, "地址：${item.customer?.detail_address.orEmpty()}")
        holder.setText(R.id.tvPlanDate, "计划时间：${item.plan_at.orEmpty()}")
        holder.setText(
            R.id.tvUser,
            item.users?.find { it.is_master == 1 }?.user?.username ?: "无"
        )
        holder.itemView.click {
            itemClick.invoke(item)
        }
    }
}